<template>
  <div>
    <h2>Home页面</h2>
    <div class="box">
      <span>登录</span>
      <div class="content">
        <input type="text" class="input" @input="addUsername" placeholder="用户名/手机号" />
        <input type="text" class="input" @input="addPassword" placeholder="密码" />
      </div>
      <div class="footer">
        <button @click="login">登录</button>
        <button @click="Register">注册</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const username = ref("");
const password = ref("");

//跳转注册路由
const Register = () => {
  router.push({ path: "/register" });
};

const addUsername = (event) => {
  let name = event.target.value.trim();
  username.value = name;
};
const addPassword = (event) => {
  let name = event.target.value.trim();
  password.value = name;
};

const login = () => {
  if (username.value == "" && password.value == "") {
    alert("你还没有输入账号或密码");
    return;
  }else{
    alert('登录成功！！！')
    //跳转登录路由
    router.push({ path: "/about" });
  }
};
</script>

<style lang="scss" scoped>
.box {
  width: 300px;
  height: 200px;
  border: 1px solid skyblue;
  border-radius: 10px;
  margin-left: 50px;
  font-size: 25px;
  span {
    display: block;
    text-align: center;
    margin-bottom: 10px;
  }
  .content {
    text-align: center;
    margin: 10px 0;
    .input{
      width: 250px;
      height: 25px;
      margin: 3px 0;
    }
  }
  .footer {
    display: flex;
    justify-content: space-around;
  }
}
</style>